package com.author.document.style;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.swing.JComponent;
import javax.swing.text.Style;

/**
 * This class will have the name of all the styles in string format. It will
 * also have a style name to font size mapping. The actual style name to style
 * mapping is also kept as part of this class.
 */
public class DefaultStyleConstant {
	/**
	 * Name of all the document styles in string format
	 */
	public final static String				HEADING_1_STYLE				= "Heading1";
	public final static String				HEADING_2_STYLE				= "Heading2";
	public final static String				HEADING_3_STYLE				= "Heading3";
	public final static String				HEADING_4_STYLE				= "Heading4";
	public final static String				NORMAL_STYLE				= "Normal";
	public final static String				PARAGRAPH_STYLE				= "Paragraph";

	/**
	 * Font size corresponding to various styles
	 */
	public static final int					HEADING_1_STYLE_FONT_SIZE	= 24;
	public static final int					HEADING_2_STYLE_FONT_SIZE	= 22;
	public static final int					HEADING_3_STYLE_FONT_SIZE	= 20;
	public static final int					HEADING_4_STYLE_FONT_SIZE	= 18;
	public static final int					NORMAL_STYLE_FONT_SIZE		= 15;
	public static final int					PARAGRAPH_STYLE_FONT_SIZE	= 15;

	/**
	 * The following map will give the size of the font corresponding to a style
	 */
	protected static Map<String, Integer>	mapStyleNameToFontSize		= new HashMap<String, Integer>();

	/** Static initialization of the above map */
	static {
		mapStyleNameToFontSize.put(HEADING_1_STYLE, HEADING_1_STYLE_FONT_SIZE);
		mapStyleNameToFontSize.put(HEADING_2_STYLE, HEADING_2_STYLE_FONT_SIZE);
		mapStyleNameToFontSize.put(HEADING_3_STYLE, HEADING_3_STYLE_FONT_SIZE);
		mapStyleNameToFontSize.put(HEADING_4_STYLE, HEADING_4_STYLE_FONT_SIZE);
		mapStyleNameToFontSize.put(NORMAL_STYLE, NORMAL_STYLE_FONT_SIZE);
		mapStyleNameToFontSize.put(PARAGRAPH_STYLE, PARAGRAPH_STYLE_FONT_SIZE);
	}

	/**
	 * Name of the default font - this will not change. It is independent of
	 * user choice
	 */
	public static final String				DEFAULT_STYLE_FONT_NAME		= new String(
																				"SansSerif");

	/**
	 * Name of the default style for the document - which is the "Normal" style.
	 */
	public static final String				DEFAULT_STYLE				= NORMAL_STYLE;

	/**
	 * Given the name of a style name in string format, gives back the font size
	 * associated with the style name
	 */
	public static int getFontSizeForStyleName(String styleName) {
		if ((styleName == null) || (styleName.length() == 0)) {
			return (Integer) mapStyleNameToFontSize.get(NORMAL_STYLE);
		}
		if (mapStyleNameToFontSize.get(styleName) == null) {
			return (Integer) mapStyleNameToFontSize.get(NORMAL_STYLE);
		}
		return (Integer) mapStyleNameToFontSize.get(styleName);
	}

	/**
	 * If a new style is added then it has to be through this method of the
	 * DefaultStyleConstant class. The style also needs to have its font size
	 * defined when the addition is done.
	 */
	public static int addStyle(String stylename, int stylefontsize) {
		if (mapStyleNameToFontSize.containsKey(stylename)) {
			throw new RuntimeException("Style with the given name already "
					+ "exists");
		}
		mapStyleNameToFontSize.put(stylename, stylefontsize);
		return 1;
	}

	/**
	 * Get the name of all the styles defined inside DefaultStyleConstant class.
	 * This returns an array of all the styles that are currently defined inside
	 * StyleConstants.
	 */
	public static String[] getAllStyles() {
		if (mapStyleNameToFontSize == null) return null;
		Set<String> keyset = mapStyleNameToFontSize.keySet();
		if ((keyset == null) || (keyset.size() == 0)) return null;
		String[] styles = new String[keyset.size()];
		int count = 0;
		for (String keys : keyset)
			styles[count++] = keys;
		return styles;
	}

	/**
	 * Remove a style name from the list of styles. This is not implemented yet,
	 * not sure if this is needed.
	 */
	public static void removeStyle(String styleName) {
	}
}